package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.db.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//服务提供者
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    //根据手机号码查询用户
    public User findByMobile(String mobile) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile", mobile);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    @Override//新用户的信息保存
    public Long save(User user) {
        userMapper.insert(user);
        System.out.println("保存用户id="+user.getId());
        return user.getId();
    }

    @Override//更新用户信息
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override//查询所有用户信息
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    @Override//根据id查询用户;
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    @Override//根据id更新手机号
    public void updatePhoneById(User user) {
        userMapper.updateById(user);
    }
}
